import requests


# 员工管理模块  接口对象层
class TestIhrmADUS():
    # 添加员工
    @classmethod
    def add_tmp(cls, header, json_data):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        resp = requests.post(url=url, headers=header, json=json_data)
        return resp

    # 查询员工
    @classmethod
    def select_tmp(cls, emp_id, header_query):
        url_query = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        resp_query = requests.get(url=url_query, headers=header_query)
        return resp_query

    # 修改员工
    @classmethod
    def update_tmp(cls, emp_id, header_modify, modify_json):
        url_modify = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        resp_modify = requests.put(url=url_modify, headers=header_modify, json=modify_json)
        return resp_modify

    # 修改员工
    @classmethod
    def delete_tmp(cls, emp_id, header_delete):
        url_delete = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        resp_delete = requests.delete(url=url_delete, headers=header_delete)
        return resp_delete


if __name__ == '__main__':
    header = {"Content-Type": "application/json", "Authorization": "Bearer 6117cb46-82c2-4be4-a3ae-99cca544c45c"}
    data_add = { "username": "业务猪019", "mobile": "13976764986", "workNumber": "9527" }
    resp = TestIhrmADUS.add_tmp(header, data_add)
    print("添加：", resp.json())

    emp_id = "1509457261905436672"
    resp = TestIhrmADUS.select_tmp(emp_id, header)
    print("查询：", resp.json())


    data = {"username": "齐天大圣"}
    resp = TestIhrmADUS.update_tmp(emp_id, header, data)
    print("修改：", resp.json())
    resp = TestIhrmADUS.delete_tmp(emp_id, header)
    print("删除：", resp.json())